import json

from django.http import JsonResponse
from django.shortcuts import render

# Create your views here.
from django.views import View

# 城区列表选择
from homes.models import Area


# 如果导包出现问题,请联系祥哥比对路径




# 城市列表视图
class CitylistView(View):

    def get(self, request):
        citys = Area.objects.all()
        city_list = []
        for city in citys:
            city_list.append({
                'aid':city.id,
                'aname':city.name
            })
        return JsonResponse({
    "errmsg": "获取成功",
    "errno": "0",
    "data": city_list


})



# 3.1发布房源视图
class PutawayView(View):
    def post(self, request):
        # 提取参数
        data = json.loads(request.body.decode())
        tit = data.get('title')
        price = data.get('price')
        area_id = data.get('area_id')
        address = data.get('address')
        room_count = data.get('room_count')
        acreage = data.get('acreage')
        unit = data.get('unit')
        capacity = data.get('capacity')
        beds = data.get('beds')
        deposit = data.get('deposit')
        min_days = data.get('min_days')
        max_days = data.get('max_days')
        
        # 校验参数



# from haystack.views import SearchView
# class MySearchView(SearchView):
#     def get(self,request):
#







